package nc.hw;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class HJ26 {

    private static String sort(String str) {
        LinkedList<Character> lists = new LinkedList<>();
        char[] chars = str.toCharArray();
        for (int i = 0; i < 26; i++) {
            for (char aChar : chars) {
                if (aChar - i == 'A' || aChar - i == 'a') {
                    lists.add(aChar);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (char aChar: chars) {
            if (aChar >= 'A' && aChar <= 'Z') {
                Character character = lists.removeFirst();
                sb.append(character);
            } else if (aChar >= 'a' && aChar <= 'z') {
                Character character = lists.removeFirst();
                sb.append(character);
            } else {
                sb.append(aChar);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(sort("A Famous Saying: Much Ado About Nothing (2012/8)."));
    }

}
